package com.example.kotlinmvvm

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class MainViewModel : BaseViewModel() {

    val userName = MutableLiveData("")

    fun refreshUserName() {
        viewModelScope.launch(Dispatchers.IO) {
            fetchUserNameAsync()
        }
    }

    suspend fun fetchUserNameAsync() {
        delay(5000)
        userName.postValue("Hello")
    }
}